﻿Imports Training.Common

Partial Public Class AddEditQuizQuestions
    Inherits System.Web.UI.Page
    Dim qid As Integer ' quizid
    Dim qnm As String ' quizname

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' check for querystring data
        If IsNothing(Request.QueryString("qid")) Or IsNothing(Request.QueryString("qnm")) Then
            Response.Redirect("QuizControl.aspx")
        Else
            qnm = Request.QueryString("qnm")
            lblQuiz.Text = qnm
            qid = Request.QueryString("qid")
            hypAddQuizQuestion.NavigateUrl = "AddNewQuizQuestion.aspx?qid=" & qid & "&qnm=" & qnm
        End If

        ' clear session variables
        Session("qid") = Nothing
        Session("qsid") = Nothing
        Session("qnm") = Nothing
        Session("qst") = Nothing
        Session("qor") = Nothing
    End Sub

    ''' <summary>
    ''' Display link to view question image
    ''' </summary>
    ''' <param name="inm"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ViewImage(ByVal inm) As String
        Dim retVal As String
        retVal = String.Empty

        If inm Is DBNull.Value Then
            retVal = String.Empty
        Else
            retVal = "<a href=""javascript:void(0);"" onclick=""window.open('../images/quizzes/full/" & inm & "','_blank','width=500,height=600,menubar=0,location=0,resizable=0,scrollbars=0');"">view</a>"
        End If

        Return retVal
    End Function

    ''' <summary>
    ''' Display link to edit question answers
    ''' </summary>
    ''' <param name="qsid"></param>
    ''' <param name="qs"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function AnswersLink(ByVal qsid As Integer, ByVal qs As String, ByVal qor As Integer) As String
        Dim retVal As String
        retVal = "<a href=""EditQuizQuestAns.aspx?qid=" & qid & "&qsid=" & qsid & "&qnm=" & qnm & "&qst=" & Replace(qs, "?", "") & "&qor=" & qor & """>edit</a>"

        Return retVal
    End Function

    ''' <summary>
    ''' Display link  to delete quiz question
    ''' </summary>
    ''' <param name="qsid"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function DeleteLink(ByVal qsid As Integer) As String
        Dim retVal As String
        retVal = "<a href=""DeleteQuizQuestion.aspx?qid=" & qid & "&qsid=" & qsid & "&qnm=" & qnm & """>delete</a>"

        Return retVal
    End Function
End Class